<template>
	<ynet-content id="sysAuth" :headerInformation="true" :headerMenu="true" class="main-container">
        <div >
			<ynet-breadcrumb></ynet-breadcrumb>
		</div>   
        <div>
            <el-dialog title="Tran Code" :visible.sync="bsnCodeTableVisible" :close-on-click-modal="false" :close-on-press-escape="false">
                <el-tree :props="defaultProps" :data="roleBsnList" node-key="bsnCode" ref="tree"
                show-checkbox 
                check-strictly 
                :default-expand-all="true"
                @check-change="handleSelectChange"
                >
                </el-tree>
                <div class="btnArea mt20 tac">
                    <el-button @click=" getBsnName()">Confirm</el-button>
                </div>
            </el-dialog>
        </div>
		<div v-if="main">
            <el-form ref="queryForm" :model="queryForm" class="formEmbedTable mt20" :rules="rules">
                <table>
                    <caption>Enquiry</caption>
                    <tr colspan="3">	
                        <td>Tran Code</td>
                        <td >
                            <el-form-item prop="inputBsnName"><el-input v-model="queryForm.inputBsnName" @focus="cleanOther()"></el-input></el-form-item>
                            <span class="btnArea">
                                <el-button @click="queryBsnList()">Search</el-button>
                            </span>
                        </td>					
                    </tr>
                        <tr>
                        <td>Date：</td>
                        <td colspan="3">
                            <el-form-item  prop="startDateObj">
                            <el-date-picker v-model="queryForm.startDateObj" @change="queryForm.startTime=$tools.utils.formatDate(queryForm.startDateObj)" type="date" placeholder="Start time"></el-date-picker>
                            </el-form-item>
                            <span>TO</span>
                            <el-form-item  prop="endDateObj">
                            <el-date-picker v-model="queryForm.endDateObj" @change="queryForm.endTime=$tools.utils.formatDate(queryForm.endDateObj)" type="date" placeholder="End Time"></el-date-picker>
                            </el-form-item>               
                        </td>
                    </tr>	
                </table>
            </el-form>
            <div class="btnArea mt20 tac">
                <el-button type="primary" @click="query()">Search</el-button>
            </div>
            <div class="tableForm tableData mt20" width="100%">
                <el-table :data="authorResultList" border >
                    <el-table-column label="Transaction Sequence No." prop="flowNo" align="center" width="300%">
                        <template scope="scope">
                            <el-button type="text" @click="openDetail(scope.$index,scope.row)"><p class="cBlue">{{scope.row.flowNo}}</p></el-button>
                        </template>
                    </el-table-column>  
                    <el-table-column label="Transaction Type" prop="bsnName" align="center"></el-table-column>  
                    <el-table-column label="submitor" prop="submit" align="center"></el-table-column>  
                    <el-table-column label="Submission Time" prop="submitTime" align="center">
                        <template scope="scope">
                            {{$tools.utils.formatDate(scope.row.submitTime,{"symbol":"YYYY-MM-DD HH:mm"})}}
                        </template>
                    </el-table-column>
                    <el-table-column label="Auth Operator" prop="authName" align="center"></el-table-column>  
                    <el-table-column label="Auth Time" prop="authTime" align="center">
                        <template scope="scope">
                            {{$tools.utils.formatDate(scope.row.authTime,{"symbol":"YYYY-MM-DD HH:mm"})}}
                        </template>
                    </el-table-column> 
                    <el-table-column label="Auth Result" prop="status" align="center">
                        <template scope="scope">
                            {{scope.row.status==0?"waiting auth":scope.row.status==1?"refuse":"approve"}}
                        </template>
                    </el-table-column>
                    <el-table-column label="reason" prop="rejReason" align="center"></el-table-column> 
                </el-table>
            </div>
            <div class="pagination tar mt20">
                <el-pagination  @current-change="handleCurrentChange" :current-page="Number(queryForm.currentPage)" :page-size="Number(queryForm.turnPageShowNum)" layout="total, prev, pager, next, jumper" :total="Number(turnPageTotalNum)">
                </el-pagination>
            </div>
            
		</div>

        <BranchDetail v-if="IM0101" :detailData="detailData" @back="back"></BranchDetail> <!-- 机构管理-->
        <RoleDetail v-if="IM0102" :detailData="detailData"  @back="back"></RoleDetail> <!-- 角色详情页-->
        <UserDetail v-if="IM0103" :detailData="detailData"  @back="back"></UserDetail><!-- 操作员管理 -->
        <AuthModelDetail v-if="IM0104" :detailData="detailData"  @back="back"></AuthModelDetail> <!-- 授权模式-->

        <AccessDetail v-if="IM0201" :detailData="detailData"  @back="back"></AccessDetail> <!-- 访问频率控制-->
        <MacConnDetail v-if="IM0202" :detailData="detailData"  @back="back"></MacConnDetail> <!-- 最大连接数-->
        <SystemParam v-if="IM0203" :detailData="detailData"  @back="back"></SystemParam><!-- 应用参数 -->
        <ApplyParam v-if="IM0204" :detailData="detailData"  @back="back"></ApplyParam> <!-- 台风标识-->
        <Typhoon v-if="IM0205" :detailData="detailData"  @back="back"></Typhoon><!-- 节假日维护 -->
        <Holiday v-if="IM0206" :detailData="detailData"  @back="back"></Holiday><!-- 节假日维护 -->

        <RequestPinDetail v-if="IM0405" :detailData="detailData"  @back="back"></RequestPinDetail> <!-- 银行限额-->

        <BankLimitDetail v-if="IM0502" :detailData="detailData"  @back="back"></BankLimitDetail> <!-- 银行限额-->
        <AccLimitDetail v-if="IM0501" :detailData="detailData"  @back="back"></AccLimitDetail> <!-- 账号限额-->
	</ynet-content>
</template>

<script>
    import BranchDetail from './details/IM0101Detail';
    import RoleDetail from "./details/IM0102Detail";
    import UserDetail from "./details/IM0103Detail";
    import AuthModelDetail from "./details/IM0104Detail";

    import AccessDetail from './details/IM0201Detail';
    import MacConnDetail from './details/IM0202Detail';
    import SystemParam from './details/IM0203Detail';
    import ApplyParam from './details/IM0204Detail';
    import Typhoon from './details/IM0205Detail';
    import Holiday from './details/IM0206Detail';

    import RequestPinDetail from './details/IM0405Detail';

    import BankLimitDetail from './details/IM0502Detail';
    import AccLimitDetail from './details/IM0501Detail';
	export default {
		name:'Authorizaiton',
		components:{
            BranchDetail,
            RoleDetail,
            UserDetail,
            AuthModelDetail,

            AccessDetail,
            MacConnDetail,
            SystemParam,
            ApplyParam,
            Typhoon,
            Holiday,

            RequestPinDetail,

            BankLimitDetail,
            AccLimitDetail,
		},
        
		data(){
            return {
                turnPageTotalNum:'',bsnCodeTableVisible:false,
                main:true,IM0101:false,IM0102:false,IM0103:false,IM0104:false,IM0501:false,IM0502:false,
                IM0201:false,IM0202:false,IM0203:false,IM0204:false,IM0205:false,IM0206:false,
                IM0405:false,
                rules:{
                    inputBranchNo:[
                        //{trigger:'blur',message:'required',required:true},
                        {trigger:'blur',validator:this.$tools.validator.isEngNum},
                    ],
                    startDateObj: [
                        {trigger: 'blur', validator:this.$tools.validator.dateCompare,compareList:['startDateObj','endDateObj'],vm:this,formName:'queryForm'}
                    ],
                    endDateObj: [
                        {trigger: 'blur', validator:this.$tools.validator.dateCompare,compareList:['startDateObj','endDateObj'],vm:this,formName:'queryForm'}
                    ],
                },
                authorResultList:[],
                queryForm:{
                    inputBsnCode:'',bsnCode:'IM0304',currentPage:'1',turnPageShowNum:'10',inputBsnName:'',
                    startDateObj:'',
                    endDateObj:'',
                    startTime:'',
                    endTime:'',
                },
                roleBsnList:[],
                defaultProps:{
                    children:'childrens',
                    label:'bsnName',
                },
                selectBsn:{},
                detailData: {}, //传给详情页的对象
            }   
        },
		methods:{ 
            openDetail(index, row) {
                //console.log("row:"+JSON.stringify(row))
                this.detailData=this.$tools.utils.transferJson(row.jsonStr)
                this.detailData.userAlias=row.submit;
                //console.log("detailData:"+JSON.stringify(this.detailData))
                this.main=false;
                switch(row.bsnCode){
                    case "IM0101": return this.IM0101=true;
                    case "IM0102": return this.IM0102=true;
                    case "IM0103": return this.IM0103=true;
                    case "IM0104": return this.IM0104=true;

                    case "IM0501": return this.IM0501=true;
                    case "IM0502": return this.IM0502=true;

                    case 'IM0201':  return this.IM0201=true;
                    case 'IM0202':  return this.IM0202=true;
                    case 'IM0203':  return this.IM0203=true;
                    case 'IM0204':  return this.IM0204=true;
                    case 'IM0205':  return this.IM0205=true;
                    case 'IM0206':  return this.IM0206=true;

                    case 'IM0405': return this.IM0405=true;
                }
            },
            back() {
                //返回审核页
                this.main = true;
                this.IM0101 = false;
                this.IM0102 = false;
                this.IM0103 = false;
                this.IM0104 = false;

                this.IM0201=false;
                this.IM0202=false;
                this.IM0203=false;
                this.IM0204=false;
                this.IM0205=false;
                this.IM0206=false;

                this.IM0501 = false;
                this.IM0502 = false;
                this.IM0405=false;
                //刷新审核页面
                this.queryAuth();
            },
            query(){//查询频率控制
                this.queryForm.currentPage=1
                //console.log("queryForm:"+JSON.stringify(this.queryForm))
                this.queryAuth()
            },
            handleCurrentChange(val) {//分页方法
                this.queryForm.currentPage=val;
                this.queryAuth()
            },
            queryAuth(){//打开某个单独菜单下的待审核信息
                //console.log("queryForm:"+JSON.stringify(this.queryForm))
                this.$tools.request(this,'IM0602QueryAction.do',this.queryForm).then(data=>{
                    //console.log("待审核信息:"+JSON.stringify(data))
                    if(data.body.errorCode==0){
                        this.authorResultList=data.body.authorResultList;
                        this.turnPageTotalNum=data.body.turnPageTotalNum;
                    }else{
                        this.$alert("System Error Try again", "warning",{
                            confirmButtonText: 'Confirm',
                        })
                    }   
                })
                
            },
            getBsnName(){
                this.queryForm.inputBsnCode=this.selectBsn.bsnCode;
                this.queryForm.inputBsnName=this.selectBsn.bsnName;
                this.bsnCodeTableVisible=false;
            },
            handleSelectChange(data,checked){
                //console.log("data:"+JSON.stringify(data))
                if(checked){
                    this.$refs.tree.setCheckedKeys([data.bsnCode])
                    this.selectBsn=$.extend(this.selectBsn,data);
                }
                console.log()
                //坚挺check状态
            },
            queryBsnList(){//查询角色菜单
                this.roleBsnList=this.$tools.storage.get("menu","save");
                this.roleBsnList.splice(0,1);
                this.bsnCodeTableVisible=true;
            },
            cleanOther() {
				let _this = this
				_this.$refs.queryForm.resetFields()
                //this.queryForm.inputUserNo='';
                _this.queryForm.inputBsnCode='';
                //this.imUserList=[];
			},
            
		}
	}
</script>
<style>
/*
    .el-table th {
        background: #aca2a0;
        color: #252222;
    }
    */
</style>